package FenxiaoService

import (
	"context"
	"gdshop-font-api-go/app/request/FenxiaoReq"
	"gdshop-font-api-go/library/response"
	"gdshop-font-api-go/library/tools"
	toolsDb "gdshop-font-api-go/library/tools/db"
	"github.com/gogf/gf/frame/g"
)

func WithdrawList(ctx context.Context, parames *FenxiaoReq.WithdrawList) *response.JsonResponse {
	whereMap := g.Map{
		"member_id": parames.MemberId,
	}
	switch parames.Type {
	case 3:
		whereMap["status"] = 2
		break
	case 2:
		whereMap["status"] = []string{"90", "99"}
		break
	case 1:
		whereMap["status"] = 1
		break
	default:
		break
	}
	count, err := toolsDb.GetUnSafaTableAddDeleteWhere(ctx, "fenxiao_withdraw").
		Fields("1").Where(whereMap).Count()
	if err != nil {
		return response.FailByRequestMessage(nil, err.Error())
	}
	all, err := toolsDb.GetUnSafaTableAddDeleteWhere(ctx, "fenxiao_withdraw").Where(whereMap).
		Fields("withdraw_no,money,handling_fee,amount_received,status,apply_time").
		Page(parames.Page, parames.PageSize).Order("id DESC").All()
	if err != nil {
		return response.FailByRequestMessage(nil, err.Error())
	}

	return response.SuccessByRequestMessageData(nil, "", g.Map{
		"page_info": tools.GetPageInfo(count, parames.Page, parames.PageSize),
		"list":      all.List(),
	})
}
